import { data } from "./house";

export function getBuildHouseNum(houseObj) {
  // console.log("getBuildHouseNum", houseObj)
  let build_num = convertLetterToNum(houseObj.build_num.charAt(0))
  let unit_num = convertLetterToNum(houseObj.unit_num.charAt(0))
  // console.log("getBuildHouseNum", `${build_num}-${unit_num}-${houseObj.house_num}`)
  return `${build_num}-${unit_num}-${houseObj.house_num}`
}

function convertLetterToNum(letter) {
  let lnMap = {一: 1, 二: 2, 三: 3, 四: 4, 五: 5, 六: 6, 七: 7, 八: 8, 九: 9, 十: 10, 十一: 11, 十二: 12,}
  return lnMap[letter]
}

//通过house对象获取楼房号>>>返回：7-4-1222
export function getBuildHouseObj(house) {
  let build_num_str = data.buildings.find(build => build.value === house.build_num).label
  let unit_num_str = data.unitList.find(unit => unit.value === house.unit_num).label
  let build_house_num = `${house.build_num}-${house.unit_num}-${house.house_num}`
  return {...house, build_num_str, unit_num_str, build_house_num}
}

//通过楼房号获取：楼号、单元号、房号>>>返回：{}
export function getHouseInfo(build_house_num_str) {
  let info_list = build_house_num_str.split("-")
  let [build_num, unit_num, house_num] = info_list
  return {build_num, unit_num, house_num}
}

export function navBack() {
  setTimeout(() => {
    uni.navigateBack({delta: 1})
  }, 700)
}
